import axios from "axios"

/**
 * 创建axios实例
 */
const service = axios.create({
    baseURL: 'https://www.quanzhan.site:8889/api/v1',
    timeout: 2000
})

/**
 * 请求拦截
 */
service.interceptors.request.use(config => {

    // config.headers.Authorization = 'bearer ' + token

    return config
}, error => {
    return Promise.reject(error)
})

/**
 * 响应拦截
 */
service.interceptors.response.use(response => {
    if(response.status === 200) {
        const { code, data, message } = response.data
        if(code === 200) {
            return data
        }
        return Promise.reject(new Error(message))
    }

    return Promise.reject(new Error('请求异常，状态码：' + response.status))
}, error => {
    return Promise.reject(error)
})

export default service